//Ta Duc Viet
//Nhap, hien thi, copy, tinh do lech chuan cua mang
#include <iostream>
#include <cmath>
using namespace std;

void input_array ( int [], int n);// nhap n phan tu vao mang
void display_array( int [], int n );// In ra n phan tu dau tien cua mang
void copy_array( int [], int [], int n);// copy n phan tu dau tien tu mang 1 vao mang 2
float standard_deviation( int [], int n);//Tinh do lech chua n phan tu dau tien cua mang
float average( int a[], int n);// Tinh gia tri trung binh cua n phan tu dau tien cua mang

int main(){
	int *a, *b;
	int n, m , n1;
	cout << "So phan tu mang 1:";
	cin >> n;
	a = new int [n];
	input_array ( a, n);
	cout << "Hien thi n phan tu  dau tien mang 1. n =";
	cin >> n1;
	while ( n1 > n){
		cout << "So phan tu hien thi phai nho hon so phan tu ban dau" << endl;
		cout << "Hien thi n phan tu  dau tien mang 1. n =";
		cin >> n1;
	}
	display_array (a, n1);
	cout << endl;
	cout << "Copy n phan tu dau tien tu mang 1 vao mang 2. n = ";
	cin >> m;
	while ( m > n){
		cout << "So phan tu copy phai nho hon so phan tu ban dau" << endl;
		cout << "Copy n phan tu dau tien tu mang 1 vao mang 2. n = ";
		cin >> m;
	}
	b = new int [m];
	copy_array ( a, b, m);
	cout << "Cac phan tu mang 2:";
	display_array ( b, m);
	cout << endl;
	cout << "Tinh do lech chuan n phan tu dau tien mang 1. n = ";
	cin >> m;
	while ( m > n){
		cout << "So phan tu de tinh phai nho hon so phan tu ban dau" << endl;
		cout << "Tinh do lech chuan n phan tu dau tien mang 1. n = ";
		cin >> m;
    }
    cout << "Do lech chuan cua " << m << "phan tu dau tien mang 1 la:" << standard_deviation (a, m);
	cout << endl;
	system("pause");
	return 0;
}

void input_array ( int a[], int n){
	for ( int i = 0; i < n ; i++){
		cout << "[" << i + 1 << "] =";
		cin >> a[i];
	}
}
void display_array( int a[], int n){
	for ( int i = 0; i < n; i++){
		cout << a[i] << "   ";
	}
}
void copy_array( int a[], int b[], int m){
	for ( int i = 0; i < m; i++){
		b[i] = a[i];
	}
}
float average( int a[], int n){
	float ave, sum;
	sum = 0;
	for ( int i = 0; i < n; i++){
        sum = sum + a[i];
        }
    return sum / n;
}
float standard_deviation (int a[], int n){
	float ave, sum;
	sum = 0;
	ave = average(a, n);
	for ( int i = 0; i < n; i++){
		sum = sum + pow (a[i] - ave,2);
	}
	return sqrt( sum / n);
}
